home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / text / print / post_src_186enh.lha / postlib.doc < prev    next >
Text File  |  1993-01-27  |  13KB  |  301 lines

  1. PostScript shared library interface (post.library, with Post V1.7)
  2. ==================================================================
  3.  
  4. Copyright Adrian Aylward 1991, 1992.
  5.  
  6. Free use and non-commercial reproduction of the binaries of the interpreter
  7. library (post.library) is permitted, providing that the copyright notices
  8. are not removed.  Distribution by disk libraries is permitted provided only
  9. a nominal copying fee is charged.
  10.  
  11. All other rights are reserved.
  12.  
  13. Introduction
  14. ============
  15.  
  16. The file "post.library" is an Exec library containing the PostScript
  17. interpreter.  It is designed to be shareable between different processes,
  18. supporting arbitrarily many PostScript activations - at least until you
  19. run out of memory.
  20.  
  21. This file should be read in conjunction with the header file "postlib.h".
  22.  
  23. The standard user interface source files are distributed with Post.  Read
  24. them as examples.
  25.  
  26. Activation Records
  27. ==================
  28.  
  29. Simultaneous multiple activations of PostScript are allowed.  Before using
  30. post.library you must first open it by a call to OpenLibrary.  To create
  31. an activation you then call PScreateact which returns a pointer to the
  32. activation record.  You can then make calls to the interpreter library,
  33. passing the activation record pointer as an argument.  You can create
  34. several activations, possibly from different processes and intermingle
  35. the interpreter calls if you wish.  When you have finished with an
  36. activation, call PSdeleteact to delete it and free the memory it used.
  37. When you have finished with the library call CloseLibrary; if no other
  38. processes have it open, then Exec can remove it from memory if the space
  39. is needed.  (N.B. if the space is not needed, the library will remain in
  40. memory in case it is opened again.)
  41.  
  42. N.B. the library can only be called from a process, as it calls various
  43. AmigaDOS functions.  It should be possible to pass activation records
  44. between processes (I think) but I have not tested it.
  45.  
  46. The Parameter Block
  47. ===================
  48.  
  49. The parameter block is the argument to PScreateact.  It is specifies the
  50. addresses of the bitmap planes, size of the page, and the amount of memory
  51. to be allocated for the activation etc..  Its format is defined in the
  52. header file.
  53.  
  54. N.B. all ints are 32 bits, shorts are 16 bits.
  55.  
  56. The page size is limited to 30000 pixels.  The densities (pixels per inch)
  57. may be any strictly positive integer value.  The y direction may be set
  58. to +1 - if the bitmap rows are in PostScript order (bottom row first) or
  59. -1 - Amiga order (top row first).
  60.  
  61.     page.buf[24]        Bitplane pointers, up to 24
  62.     page.len            Size in bytes of each plane
  63.     page.depth          Number of planes (must be 1,3,4)
  64.     page.reserved       Reserved, must be zero
  65.     page.xbytes         Number of bytes in each row
  66.     page.xsize          Number of pixels in each row
  67.     page.ysize          Number of rows
  68.     page.ybase          Base of current band
  69.     page.yheight        Total height of full page, for band rendering
  70.     page.xden           X density
  71.     page.yden           Y density
  72.     page.ydir           Y direction
  73.  
  74. As a starting point for memory sizes try the values following.  (These are
  75. defined in the header file.)  For normal PostScript programs the defaults
  76. are perfectly satisfactory.  If you specify a value of zero the default
  77. will be used instead; values less than the minimum will be increased.
  78.  
  79.     memvlen     50000   VM
  80.     memflen     60000   Font cache
  81.     memllen     10000   Path lines
  82.     memhlen     20000   Halftones
  83.  
  84. The user data pointer is intended to be used to identify multiple
  85. activations.  You can set it to any value you like.  The function pointers
  86. are described below.
  87.  
  88.     userdata            User data pointer
  89.     flushfunc           Flush page function pointer
  90.     copyfunc            Copy page function pointer
  91.  
  92. The standard input and output streams are the DOS file handles to be used
  93. by the interpreter for %stdin, %stdout, %stderr.  Also the standard output
  94. is used for prompts and the error output for error messages.
  95.  
  96.     infh                Standard Input file handle
  97.     outfh               Standard Output file handle
  98.     errfh               Standard Error file handle
  99.  
  100.     funcmax             Number of external functions
  101.     functab             Pointer to external function table, or zero
  102.  
  103. The rest of the block is reserved and must be set to zero.
  104.  
  105. Function Pointers
  106. =================
  107.  
  108. There are two function pointers within the parameter block, which are used
  109. when the interpreter needs to call routines supplied by its client.  If
  110. the pointers are zero the calls are skipped.
  111.  
  112. To help identify calls from multiple activations, the activation record
  113. address is also passed in a0 and the userdata pointer in a1.
  114.  
  115.       flushfunc(d0: int y1, d1: int y2)
  116.  
  117. Flush the bitmap to the screen.  The interpreter calls this function after
  118. a painting operation has updated the bitmap.  Then if the output is being
  119. viewed interactively the client can update the screen or window.  The
  120. arguments are the range of bitmap rows (y1 ... y2-1) that may have been
  121. updated.
  122.  
  123.       copyfunc(d0: int num)
  124.  
  125. Copy the page to the output device.  The argument is the value of #copies,
  126. which should be taken into account if the output is to a printer, but is
  127. not meaningful for screen output.
  128.  
  129. Calling External Functions
  130. ==========================
  131.  
  132. If you supply an external function table your PostScript program can call
  133. the functions within it by the "callextfunc" operator.  The contents of the
  134. table are the addresses of the function entry points.  The functions must
  135. have standard (Lattice, non-registerised) C compatible calling sequences.
  136. They must not assume any useful value in register A4 on entry, and must
  137. preserve A4 and the other C registers on exit.
  138.  
  139. Only certain PostScript objects may be passed as arguments: integers reals
  140. and booleans are passed as the 32 bit bitpatterns corresponding to their
  141. values; arrays and strings are passed as the 32 bit address of their
  142. contents - if the length is required it must be passed separately.  (N.B.
  143. PostScript strings are terminated by length; there is no terminating null
  144. unless the program puts one there.)
  145.  
  146. It is possible to pass arbitrary objects my including them within an array,
  147. but then you have to know their PostScript representation.
  148.  
  149. The "callextfunc" operator is only inserted into the system dictionary if
  150. a function table is present.  So you will not find it if you attempt to
  151. execute it from the standard user interface.
  152.  
  153. Library Entry points
  154. ====================
  155.  
  156. Prototypes and pragmas for the entry points are defined in the header file.
  157.  
  158.   Create a PostScript activation
  159.  
  160.           d0:int arec = PScreateact(a1:struct PSparm *parm)
  161.  
  162. The result is the address of the new activation record.  If the activation
  163. fails an error code is returned instead - zero if the interpreter failed
  164. to start at all because there was insufficient free memory, or an
  165. interpreter error code if there was an error during initialisation.
  166. Otherwise the result is the address of the activation record.  The result
  167. is always returned as an int.  If is is greater than errmax then the
  168. activation was successful, and the value is an address; otherwise the
  169. activation failed, and the result is zero or an error code.
  170.  
  171.   Delete a PostScript activation
  172.  
  173.           PSdeleteact(a0:APTR arec)
  174.  
  175. The activation record is deleted and the associated memory is freed.
  176.  
  177.   Interpret a string or file
  178.  
  179.           d0:int errnum = PSintstring(a0:APTR arec, a1:char *string,
  180.                                       d0:int length, d1:int flags)
  181.  
  182. If the flag PSFLAGSTRING is set, the contents of the string are interpreted
  183. as PostScript source.  If the flag PSFLAGFILE is set, the string is a file
  184. name, whose contents are interpreted.  If neither of these flag bits are set
  185. the string is ignored, but the other flag bits still have their effects; if
  186. both are set the result is undefined.
  187.  
  188. If PSFLAGINTER is set (when interpreting a file), the file is considered to
  189. be interactive.  The banner is printed, and the interpreter prompts for each
  190. line of input from the file.
  191.  
  192. If PSFLAGCLEAR is set, then after interpretation the operand stack is
  193. cleared and the dictionary stack is popped until only the system and user
  194. dictionaries remain.
  195.  
  196. If PSFLAGESAVE is set, the vm is saved before interpretation begins and
  197. restored afterwards.  You would normally use PSFLAGCLEAR with this option,
  198. to prevent invalidrestore errors.
  199.  
  200. If PSFLAGERASE is set, then the page is erased.  This happens right at the
  201. end, after any vm restore, so the page is erased taking into account the
  202. restored transfer function(s).
  203.  
  204. This routine is not guaranteed to recurse correctly; strange things may
  205. happen if you try to call it from an external function called from the
  206. same activation.
  207.  
  208.   Signal an interrupt
  209.  
  210.           PSsignalint(a0:APTR arec, d0:int flag)
  211.  
  212. This routine may be called to set (flag = 1) or clear (flag = 0) the
  213. interrupt signal flag.  The interpreter tests this flag at the head of its
  214. main loop, and also within certain potentially length operators (=, ==,
  215. stack and pstack).  If the flag is set it generates an interrupt error.
  216. You may safely call this routine at any time during the life of the
  217. activation.  It is intended to be called from within your task's
  218. exception handler, if the CTRL/C break signal is set.
  219.  
  220.   Signal a floating point error
  221.  
  222.           PSsignalfpe(a0:APTR arec)
  223.  
  224. This routine is intended to be called whenever a floating point trap is
  225. generated by the interpreter.  It generates an immediate undefinedresult
  226. error.  You must not call it at any other time; if you do you will crash
  227. the machine.  It is only useful if you are using the version of the library
  228. compiled for the 68881 FPU or compatible chips.  (The software floating
  229. point routines do not generate traps).  Before calling the library you
  230. should set up a trap handler and set the bits in the fpcr register to
  231. enable the traps.  (If you do not set up the traps, the FPU will substitute
  232. the special value not-a-number for the result and continue.  The
  233. undefinedresult error will not be triggered, and results of your program
  234. may be incorrect.)  If you application does not use the FPU you can simply
  235. direct all traps to the library, otherwise it is essential that you
  236. ensure that you only call this routine if the trap derived from the library
  237. and not your own code.
  238.  
  239.   Error
  240.  
  241.           PSerror(a0:APTR arec, d0:int errnum)
  242.  
  243. This routine is intended to be called from within your own flush or copy
  244. page functions, to signal that an error ocurred.  You can also call it from
  245. an external function.  You must not call it at any other time; if you do you
  246. will crash the machine.  It calls the PostScript error handler and never
  247. returns.  The values for the error number are defined in the header file.
  248.  
  249.   Allocate virtual machine memory
  250.  
  251.           d0:unsigned vref = PSallocvm(int arec, int size)
  252.  
  253. Allocates a block of VM memory of the specified size.  The result a 32 bit
  254. abstract VM reference, suitable for use in creating PostScript objects; if
  255. you want to convert the result to a machine address you shall call
  256. PSvreftoptr.  If the memory cannot be obtained the PostScript error handler
  257. will be called and this routine will not return.  There is no corresponding
  258. to free the memory; as with all PostScript VM objects the memory remains
  259. allocated until the VM is next restore'd to an outer save level.  Abstract
  260. VM references created in one activation may not be passed to another.
  261.  
  262.   Convert VM reference to pointer
  263.  
  264.           d0:void *ptr = PSvreftoptr(int arec, unsigned vref)
  265.  
  266. Converts an abstract VM reference to a machine address pointer.
  267.  
  268.   Change device page
  269.  
  270.           PSsetdevice(a0:APTR arec, a1:struct PSdevice *page)
  271.  
  272. Changes the device page buffer and dimensions.  If the clip path is still
  273. set to its initial value (the whole page) it s changed to match the new page
  274. size; otherwise it is unchanged (and may therefore possibly exceed the new
  275. page size).  All the clip paths saved on the graphics stack are similarly
  276. changed.  The CTM at the topmost saved graphics state (the one returned to
  277. by a "grestoreall" when there are no active VM saves) is reset to match the
  278. new page size and density.  Otherwise the CTM is not affected; you will
  279. likely want to execute "initmatrix" afterwards.
  280.  
  281. The interactions of this routine with the stack of saved graphics states are
  282. complex, leading to unexpected behaviour unless you understand exactly what
  283. is happening.  So it is safest to always call it when there are no save's or
  284. gsave's active, and then to reinitialse the CTM immediately.
  285.  
  286. This routine should not be called from within a character build, kerning,
  287. or imaging procedure.
  288.  
  289.   Return a text string corresponding to an error name
  290.  
  291.           d0:char *str = PSerrstr(int arec, int errnum)
  292.  
  293. Converts a postscript error number to a text string.  Returns NULL if the
  294. number is out of range.
  295.  
  296. Versions
  297. ========
  298.  
  299. The version of the library distributed with Post V1.7 has version number 17.
  300.  
  301.